/**
 * dev（感觉作用不大）
 * 没用雪碧图和css压缩，在使用的时候要注意
 */


const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('[name].css');
const extractLESS = new ExtractTextPlugin({
    filename: '[name].css'
});

const HtmlWebpackPlugin = require('html-webpack-plugin');
const htmlWebpackPlugin = new HtmlWebpackPlugin({
    title: 'index',
    filename: 'page/index/index.html',
    template: 'page/index/index.html',
    loader: "raw-loader",
    hash: true,
});

module.exports = {
    entry: {
        'page/index/index': [
            './widgets/layout/top/top.ts',
            './widgets/content/main/main.ts',
            './widgets/layout/footer/footer.ts',
        ]
    },
    output: {
        library: {
            root: 'MyLibrary',
            amd: 'my-library',
            commonjs: 'my-common-library'
        },
        libraryTarget: 'umd',
        path: path.resolve(__dirname, 'pkg'),
        publicPath: '/pkg',
        filename: '[name].js',
    },
    resolve: {
        modules: [
            'node_modules',
            path.resolve(__dirname, 'widgets'),
            'pkg/img-sprites'
        ],
        extensions: ['.ts', '.tsx', '.jsx', '.js'],
        alias: {
            demo: path.resolve(__dirname, 'widgets/common/demo'),
            o: path.resolve(__dirname, 'widgets/common/o'),
            top : path.resolve(__dirname, 'widgets/layout/top'),
        },
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                exclude: /(node_modules|webpackConf|tsconfig|package-lock)/,
                use: 'ts-loader'
            },{
                test: /\.less$/,
                exclude: /(node_modules)/,
                use: extractLESS.extract({
                    use: [{
                        loader: 'css-loader',
                    }, {
                        loader: 'less-loader'
                    }],
                    fallback: 'style-loader'
                })
            }
        ]
    },
    plugins: [
        extractCSS,
        extractLESS,
        htmlWebpackPlugin
    ]
};
